<%@page import="com.wowangz.cms.common.utils.MessageObject"%>
<%@page import="com.wowangz.cms.common.utils.DictTypeConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/pageHead.jsp"%>

<link rel="stylesheet" href="${systemctx}/resources/webuploader/webuploader.css">
<link rel="stylesheet" href="${systemctx}/resources/css/fileupload.css">

<script type="text/javascript" src="${systemctx}/resources/webuploader/webuploader.js" charset="UTF-8" ></script>
<script type="text/javascript" src="${systemctx}/resources/js/jquery.validation.js" charset="UTF-8" ></script>

<c:set value="<%=SysConstant.CommonApproveStatus.SAVED %>" var="state"></c:set>
<c:set value="<%=SysConstant.CommonApproveStatus.REFUSED %>" var="refuse"></c:set>

<script type="text/javascript">
	$(document).ready(function() {
		$("#allperson").selectutil({
			optModel : <%=SysConstant.BoradAllperson.getBoradAllpersonModelJSONString(false, false)%>,
			optDefault : <%=SysConstant.BoradAllperson.ALL_PERSON%>
		});
		$("#sendtime").selectutil({
			optModel : <%=SysConstant.Sendtime.getSendtimeModelJSONString(true, false)%>,
			optDefault : <%=SysConstant.Sendtime.IMMEDIATELY%>
		});
		$("#savetime").selectutil({
			optModel : <%=SysConstant.LeaveMsgSaveTime.getLeaveMsgSaveTimeModelJSONString(false, false)%>,
			optDefault : <%=SysConstant.LeaveMsgSaveTime.DEFAULTTIME%>
		});
		//单位编号放大镜
		$("#storename").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.select.title") %>',
			url: '${systemctx}/publicMagnifier/publicMagnifier.json',
			sortName: 'modifytime',
			sortOrder: 'desc',
			linkName: 'number',
			callSqlKey: 'queryStoreMagnifierSql',
			changeIgnore:['storename'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>',field:'number',width:180,sortable:true,search:true,align:'left'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>',field:'name',width:180,search:true,sortable:true,align:'left',formel:'storename'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.corporate") %>',field:'corporate',width:180,search:true,sortable:true,align:'left'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.email") %>',field:'email',width:180,search:true,sortable:true,align:'left'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.telephonenumber") %>',field:'telephonenumber',width:180,search:true,sortable:true,align:'left'},
					{field:'id', hidden:true, formel:'storeId'}
			]],
			onBeforeVaild:function(p){
				if($('#storename').val() == '' || $('#storename').val() == null){
					$('#storename').val('${storename}');
				}
			},
			onBeforeOpen:function(p){
		      	var queryParams = {
		      		  name: $('#storename').val(),
		      		  state: <%=SysConstant.CommonApproveStatus.OK %>,
		    		  statusid: <%=SysConstant.RecordStatus.VALID %>,
		    		  businessstatus:<%=SysConstant.CommonUsedStatus.START %>
		      	};
		      	return queryParams; 
		    }
		});
		
		$("#allperson").change(function() {
			var diy = '<%=SysConstant.BoradAllperson.DIY%>';
			if($(this).val() == diy) {
				$("#selectStore").css({
					display : 'block'
				});
				$("#single").css({
					display : 'block'
				});
				$("#storename").addClass('validate[required]');
			} else {
				$("#selectStore").css({
					display : 'none'
				});
				$("#single").css({
					display : 'none'
				});
				$("#storename").val('');
				$("#storid").val('');
				$("#userId").val('');
				$("#loginname").val('');
				$("#noChecked").prop("checked", true);
				$("#isSingle").attr("checked", false);
				$("#selectUser").css({
					display : 'none'
				});
				$("#storename").removeClass('validate[required]');
			}
			//
		});
		$("#savetime").change(function() {
			var diy = '<%=SysConstant.LeaveMsgSaveTime.DIY%>';
			if($(this).val() == diy) {
				$("#diy_savetimesecond").css({
					display : 'block'
				});
				$("#savetimesecond").addClass('validate[required]');
			} else {
				$("#diy_savetimesecond").css({
					display : 'none'
				});
				$("#username").val('');
				$("#userId").val('');
				$("#loginname").val('');
				$("#savetimesecond").removeClass('validate[required]');
			}
			//
		});
		
		$("input[name='isSingle']").each(function(){
			var that = $(this);
			that.click(function() {
				var val = $(this).val();
				if(val == 1) {
					$("#selectUser").css({
						display : 'none'
					});
					$("#username").val('');
					$("#userId").val('');
					$("#loginname").val('');
					$("#username").removeClass('validate[required]');				
				} else {
					$("#selectUser").css({
						display : 'block'
					});
					$("#username").addClass('validate[required]');	
				}
			});
		});
		
		$("#butReturn").click(function(){
			parent.document.location.reload();
		    $.fn.closeIssWindow();
		});
		
		// 打开modal
		//单位编号放大镜
		$("#username").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.select.title") %>',
			url: '${systemctx}/jpush/queryStoreUserInfoList.json',
			sortName: 'modifytime',
			sortOrder: 'desc',
			linkName: 'userno',
			callSqlKey: 'queryStoreMagnifierSql',
			changeIgnore:['username'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.column.userno") %>',field:'userno',width:180,sortable:true,search:true,align:'left'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.column.username") %>',field:'username',width:180,search:true,sortable:true,align:'left',formel:'username'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.column.loginname") %>',field:'loginname',width:180,search:true,sortable:true,align:'left', formel:'loginname'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "systemtmanage.user.column.phone") %>',field:'phone',width:180,search:true,sortable:true,align:'left'},
					{field:'id', hidden:true, formel:'userId'}
			]],
			onBeforeOpen:function(p){
		      	var queryParams = {
		      		  storeid: $('#storeId').val(),
		      		  username: '%' + $('#username').val() + '%',
		    		  statusid: <%=SysConstant.RecordStatus.VALID %>
		      	};
		      	return queryParams; 
		    }
		});
	});
	
	/*flag == 1 表示保存，flag == 2 表示提交*/
	function save(flag){
		var exp = $('#form1').validationEngine('validate');
		if(exp==true){
			var savetimesecond = $("#savetimesecond").val();
			var maxS = <%=SysConstant.LeaveMsgSaveTime.DAY_10%>;
			if(savetimesecond > maxS) {
				alert("最大保留时间不能超过 <%=SysConstant.LeaveMsgSaveTime.getName(SysConstant.LeaveMsgSaveTime.DAY_10)%>" );
				return false;
			}
			// 显示进度条
			showSending();
			$.ajax({
				type : 'POST',
				url : '${systemctx}/jpush/sendNotices.json',
				data : $("#form1").serialize(),
				dataType : 'json',
				success : function(data) {
					//关闭执行...
					closeSending();
					console.info(data);
					if(data.resposecode == '<%=MessageObject.ResponseCode.code_200%>') {
						alert(data.message);
						parent.query_datagrid();
					    $.fn.closeIssWindow();
					} else {
						alert(data.message);
						return false;
					}
				}
			});
		}
	}
</script>
<form name="form1" id="form1" action="" method="post">
	<div class="pageMain">
		<div class="pageTitle">
			<%=MessageResourcesUtils.getMessage(request, "systemmanage.contentmanagement.title")%>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "jpush.module.title") %>
			<span></span>
			<%=MessageResourcesUtils.getMessage(request, "jpush.module.add.title") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li class="liw">
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.title") %>
						</label>
						 <span>
							<input type="text" name="title" id="title" size="30" class="validate[required,maxSize[30]]" />
						</span>
					</li>
				</ul>
				<ul>
					<li class="liw">
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.content") %>
						</label>
						<span>
							<textarea maxlength="250" name="content" class="validate[required,maxSize[250]]" id="content" 
								style="width: 500px;height: 100px;"></textarea>
						</span>		
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.allperson") %>
						</label>
						<span>
							<select name="allperson" id="allperson" class="validate[required]"></select>
						</span>
					</li>
					<li id="selectStore" style="display: none;">
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.column.name") %>
						</label>
						<span>
							<input type="hidden" name="storeid" id="storeId" />
							<input type="text" name="storename" id="storename"/>
						</span>
					</li>
				</ul>
				<ul id="single" style="display: none;">
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.store.single") %>
						</label>
						<span>
							<input style="width: 13px;height: 13px;" value="1" type="radio" checked="checked" name="isSingle" id="noChecked"/> 否
							<input style="width: 13px;height: 13px;margin-left: 15px;" value="2" type="radio" name="isSingle" id="isSingle"/> 是
						</span>
					</li>
					<li id="selectUser" style="display: none;">
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"dailyoperation.store.store.user.name") %>
						</label>
						<span>
							<input type="hidden" name="userid" id="userId" />
							<input type="text" name="username" id="username" />
							<input type="hidden" name="loginname" id="loginname"/>
						</span>
					</li>
				</ul>
				<ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.savetime") %>
						</label>
						<span>
							<select name="savetime" id="savetime" class="validate[required]"></select>
						</span>
					</li>
					<li id="diy_savetimesecond" style="display: none;">
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.savetime") %>
						</label>
						<span>
							<input type="text" id="savetimesecond" name="savetimesecond">(秒)
						</span>
					</li>
				</ul>	
				<%-- <ul>
					<li>
						<i>*</i>
						<label>
							<%=MessageResourcesUtils.getMessage(request,"jpush.module.col.sendtime") %>
						</label>
						<span>
							<select name="sendtime" id="sendtime" class="validate[required]"></select>
						</span>
					</li>
				</ul> --%>
			</div>
			<div class="button-group">
				<input type="button" class="btn btn-default" onclick="save('1')" id="butSave" name="butSave" value='<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>' />
				<input type="button" class="btn btn-default" id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
			</div>
		</div>
	</div>
</form>

<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>